package com.example.demo.controller;

import com.example.demo.job.Job;
import com.example.demo.service.QuartzService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequiredArgsConstructor
public class JobController {

    private final QuartzService quartzService;

    @GetMapping("addjob")
    public void addJob(
            String name
    ) {

        for (int i = 0; i < 15; i++) {
            HashMap<String,Object> map = new HashMap<>();
            map.put("name",name+i);
            quartzService.deleteJob(name+i, "test");
//            quartzService.addJob(Job.class, name+i, "test", "0/3 * * * * ?", map);
            quartzService.addJob(Job.class, name+i, "test",1,1,map);
            try {
                Thread.sleep(500);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }


    }

    @GetMapping("delallJob")
    public void delallJob(String name) {
        for (int i = 0; i < 1200; i++) {

            quartzService.deleteJob(name+i, "test");

        }

    }


    @GetMapping("delJob")
    public void delJob(String name) {
        quartzService.deleteJob(name, "test");
    }

    @GetMapping("getAll")
    public Object queryAllJob() {

        List<Map<String, Object>> maps = quartzService.queryAllJob();
        return maps;

    }

    @GetMapping("getRunn")
    public Object getRunn() {

        List<Map<String, Object>> maps = quartzService.queryRunJob();
        return maps;

    }

}
